package com.qining618.common.model;

import com.alibaba.fastjson.JSON;
import com.qining618.cms.ucenter.domain.Token;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.Date;

/**
 * 凭证
 * @author flt
 * @date 2019-09-16
 */
@AllArgsConstructor
@NoArgsConstructor
@Data
@Builder
@Accessors(chain = true)
public class TokenInfo implements Serializable {

    private static final long serialVersionUID = -7017571682383816762L;

    /**
     * 凭证
     */
    private String accessToken;

    /**
     * 过期时间
     */
    private Date expireTime;

    /**
     * 认证信息
     */
    private AuthUser authUser;

    public static TokenInfo of(Token token) {
        TokenInfo tokenInfo = new TokenInfo();
        tokenInfo.setAccessToken(token.getAccessToken());
        tokenInfo.setExpireTime(token.getExpireTime());
        tokenInfo.setAuthUser(JSON.parseObject(token.getAuthInfo(), AuthUser.class));
        return tokenInfo;
    }


}
